package com.geek.ch06.mapper;

import com.geek.entity.mark.User;
import com.geek.entity.mark.Orders;
import com.geek.entity.mark.OrderDetail;
import java.util.List;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface OrdersMapper {
    // 1：查询订单信息及其下单者信息
    @Select("select * from orders where id = #{oid}")
    @Results({
            // 映射 Orders 本身字段
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "user_id", property = "user", javaType = User.class,
                one = @One(select = "com.geek.ch06.mapper.UserMapper.getUserById"))
    })
    public Orders selectUserByOid(Integer oid);

    // 2.每个订单中包含的商品信息
    @Select("select * from orders where id = #{oid}")
    @Results({
            // 映射 Orders 本身字段
            @Result(id = true, property = "id", column = "id"),
            @Result(column = "id", property = "orderDetail", javaType = List.class,
                many = @Many(select = "com.geek.ch06.mapper.OrderDetailMapper.selectDetailByOid"))
    })
    public Orders selectOrderDtsByOrders(Integer oid);
}
